package han.chensing.latos.game.elements.character.impl;

import com.badlogic.gdx.graphics.Color;
import han.chensing.latos.game.elements.character.Character;
import han.chensing.latos.game.elements.character.CharacterInstance;

public class TestCharacter2 extends Character {

    float recoverRate=.5f;
    float maxRecoverRate=.5f;
    float decreaseRate=10;
    float decreaseExtra=.9f;

    int level=0;

    public TestCharacter2() {
        setMaxHealth(100);
        setDefaultHealthColor(Color.valueOf("#fd873a"));
        setDefaultHurtColor(Color.WHITE);
    }

    @Override
    public void invokeTick(CharacterInstance characterInstance, float delta) {
        defaultBufferHealthHandle(characterInstance, delta);
        defaultHuntAlphaHandle(characterInstance, delta);
        defaultShownHealthHandle(characterInstance, delta);
    }

    @Override
    public void invokeMessage(CharacterInstance characterInstance, String message) {
        switch (message){
            case "onPerfect":{
                recoverRate+=.03f;
                recoverRate=Math.min(recoverRate,maxRecoverRate);
                characterInstance.increaseHealth(recoverRate);
                break;
            }
            case "onGood":{
                characterInstance.resetHurtAlpha();
                characterInstance.decreaseHealth(decreaseRate/3f);
                if (level==0) {
                    characterInstance.setHealthColor(Color.valueOf("#3399ff"));
                    level=1;
                }
                break;
            }
            case "onBad":
            case "onMiss":{
                if (level<=1){
                    characterInstance.setHealthColor(Color.WHITE);
                    level=2;
                }
                recoverRate=0;
                characterInstance.resetHurtAlpha();
                characterInstance.setHealth(characterInstance.getHealth()*decreaseExtra);
                characterInstance.decreaseHealth(decreaseRate);
                break;
            }
        }
    }

    @Override
    public boolean isDead(CharacterInstance characterInstance) {
        return false;
    }
}
